#!/bin/sh

# $Id$

cd "$(dirname "$0")"

. functions.sh

TEST_INIT $(basename "$0")

# Check basic comment functionality. If these are not recognized as
# comments, the open parenthesis should provoke an error.

TEST <<"EOF"
; a trailing comment (

  ; a trailing comment with leading space (

; a trailing comment with trailing space (   
---
; a trailing comment (

; a trailing comment with leading space (

; a trailing comment with trailing space (
EOF

TEST <<"EOF"
#| a nested comment (
|#
  #| a nested comment with leading space (
|#
#| a nested comment with trailing space (    
|#
#| a #| doubly |# nested comment ( |#
#| a #| doubly #| and triply |#|# nested comment ( |#
---
#| a nested comment (
|#
#| a nested comment with leading space (
|#
#| a nested comment with trailing space (    
|#
#| a #| doubly |# nested comment ( |#
#| a #| doubly #| and triply |#|# nested comment ( |#
EOF

TEST <<"EOF"
#;"a datum comment"
---
#;"a datum comment"
EOF

# Check nested comment errors.

TEST_ERROR <<"EOF"
#| an unterminated nested comment
---
scheme-indent: error: while indenting: unterminated nested comment.
EOF

TEST_ERROR <<"EOF"
#| an unterminated #| doubly |# nested comment
---
scheme-indent: error: while indenting: unterminated nested comment.
EOF

# Test basic indentation of comments.

TEST <<"EOF"
;; indent 0
(a b ;; indent trailing
;; indent 3
(c
d
;; indent 4
e))
;; indent 0
#| indent 0
|#
(a b #| indent trailing |#
#| indent 3 |#
(c
d
#| indent 4 |#
e))
#| indent 0 |#
#; indent-0
(a b #; indent-trailing
#; indent-3
(c
d
#; indent-4
e))
  #; indent-0
---
;; indent 0
(a b ;; indent trailing
   ;; indent 3
   (c
    d
    ;; indent 4
    e))
;; indent 0
#| indent 0
|#
(a b #| indent trailing |#
   #| indent 3 |#
   (c
    d
    #| indent 4 |#
    e))
#| indent 0 |#
#; indent-0
(a b #; indent-trailing
   #; indent-3
   (c
    d
    #; indent-4
    e))
#; indent-0
EOF

TEST <<"EOF"
(a ;;
b
c)
(a #|
|#
b
c)
(a #| |# b
c)
---
(a ;;
 b
 c)
(a #|
|#
 b
 c)
(a #| |# b
   c)
EOF

# Check comments do not confuse indentation.

TEST <<"EOF"
(let
((a b))
c)
(let ;; a trailing comment
((a b))
c)
(let #| a nested comment |#
((a b))
c)
(let
;; a trailing comment
#| a nested comment |#
((a b))
;; a trailing comment
#| a nested comment |#
c)
(let
#; "a datum comment"
((a b))
#; "a datum comment"
c)
---
(let
    ((a b))
  c)
(let ;; a trailing comment
    ((a b))
  c)
(let #| a nested comment |#
    ((a b))
  c)
(let
    ;; a trailing comment
    #| a nested comment |#
    ((a b))
  ;; a trailing comment
  #| a nested comment |#
  c)
(let
    #; "a datum comment"
    ((a b))
  #; "a datum comment"
  c)
EOF

# Check comments don't confuse the first form.

TEST <<"EOF"
(   ;; comment
a b
c
d)
(  #| comment |# a b
c
d)
---
(   ;; comment
 a b
 c
 d)
(  #| comment |# a b
 c
 d)
EOF
